package com.gamejelly.broker.processor.message;

import com.alipay.remoting.BizContext;
import com.alipay.remoting.rpc.protocol.SyncUserProcessor;
import com.gamejelly.broker.client.BrokerClient;
import com.gamejelly.broker.message.RpcMessage;

import java.util.Map;

public class ClientRpcHandler extends SyncUserProcessor<RpcMessage> {

    Map<String, BrokerClient> clients;

    public ClientRpcHandler(Map<String, BrokerClient> clientMap) {
        this.clients = clientMap;
    }

    @Override
    public Object handleRequest(BizContext bizContext, RpcMessage message) throws Exception {
        BrokerClient client = clients.get(message.findTarget());
        if (client != null)
            client.handle(message);
        return null;
    }

    @Override
    public String interest() {
        return RpcMessage.class.getName();
    }
}
